<template>
  <a-card :bordered="false">
    <a-row :gutter="24">
      <a-col :md="leftColMd" :sm="24">

      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">

            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.system.position.entity.positionName')">
                <a-input placeholder="" v-model="queryParam.positionName$lk"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item :label="$t('m.system.position.entity.positionCode')">
                <a-input placeholder="" v-model="queryParam.positionCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
                <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" v-has="'system:SysPosition:add'" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
        <a-button @click="batchDel" v-has="'system:SysPosition:delete'" type="default"  icon="delete" v-test>{{ $t('m.common.button.delete') }}</a-button>
        <a-button type="default" v-has="'system:SysPosition:export'" icon="download" @click="handleExportXls($t('m.system.user.other.position_label'))">{{ $t('m.common.button.export') }}</a-button>
        <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                  @change="handleImportExcel">
          <a-button type="default"  v-has="'system:SysPosition:import'" icon="import">{{ $t('m.common.button.import') }}</a-button>
        </a-upload>

      </div>

      <!-- table区域-begin -->
      <div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange">
          <template slot="serialNum" slot-scope="text,record,index">
            {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
          </template>
          <span slot="action" slot-scope="text, record">
            <a @click="handleOpen(record)">{{$t('m.system.position.other.href_user')}}</a>
            <a-divider type="vertical"/>
            <a  v-has="'system:SysPosition:edit'" @click="handleEdit(record)">{{ $t('m.common.button.update') }}</a>
            <a-divider type="vertical"/>
            <a-popconfirm :title="$t('m.common.tip.delete_confirm')" v-has="'system:SysPosition:delete'" @confirm="() => handleDelete(record.id)" v-test>
              <a>{{ $t('m.common.button.delete') }}</a>
            </a-popconfirm>
          </span>

        </a-table>
      </div>
      <!-- table区域-end -->

      <!-- 表单区域 -->
      <sysPosition-modal ref="modalForm" @ok="modalFormOk"></sysPosition-modal>
      </a-col>
      <a-col :md="rightColMd" :sm="24" v-if="this.right">
        <SysPositionUserRight :position="position" @hideUserList="hideUserList"></SysPositionUserRight>
      </a-col>
    </a-row>
  </a-card>
</template>

<script>

  import {YcListMixin} from '@/mixins/YcListMixin'
  import SysPositionModal from './modules/SysPositionModal'
  import YchConstant from "@/api/YchConstant";
  import SysPositionUserRight from './SysPositionUserRight'

  export default {
    name: "SysPositionList",
    mixins: [YcListMixin],
    components: {
      SysPositionModal,
      SysPositionUserRight
    },
    data() {
      return {
        description: '职务表管理页面',
        right: false,
        position:{},
        // 表头
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.system.position.entity.positionName'),
            align: "center",
            dataIndex: 'positionName'
          },
          {
            title: this.$t('m.system.position.entity.positionCode'),
            align: "center",
            dataIndex: 'positionCode'
          },
          {
            title: this.$t('m.system.position.entity.positionOrder'),
            align: "center",
            dataIndex: 'positionOrder'
          },
          /*{
            title: '职务描述',
            align: "center",
            dataIndex: 'description'
          },*/
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'},
          }
        ],
        url: {
          list: YchConstant.PREFIX_SYSTEM + "/sysPosition/list",
          delete: YchConstant.PREFIX_SYSTEM + "/sysPosition/delete",
          deleteBatch: YchConstant.PREFIX_SYSTEM + "/sysPosition/deleteBatch",
          exportXlsUrl: YchConstant.PREFIX_SYSTEM + "/sysPosition/exportExcel",
          importExcelUrl: YchConstant.PREFIX_SYSTEM + "/sysPosition/importExcel",
        },
        dictOptions: {},
        /* 排序参数 */
        isorter: {
          column: 'positionOrder',
          order: 'asc',
        }
      }
    },
    computed: {
      importExcelUrl: function () {
        return `${bootConfig[process.env.NODE_ENV].VUE_APP_API}${this.url.importExcelUrl}`;
      },
      leftColMd() {
        return this.right ? 13 : 24
      },
      rightColMd() {
        return this.right ? 11 : 0
      },
      mdSize(){
        return this.right ? 12 : 6
      },
    },
    methods: {
      initDictConfig() {
      },
      handleOpen(record) {
        this.position = record
        this.right = true
      },
      hideUserList() {
        this.right = false
      },

    }
  }
</script>
<style lang="less" scoped>

</style>
